using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_JXC_AccountSubjectDetailMoney : Admin, IRequiresSessionState
{
	protected ScriptManager sm;
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected DropDownList ddlYear;
	protected DropDownList ddlBeginMonth;
	protected DropDownList ddlEndMonth;
	protected DropDownList ddlSubject;
	protected TextBox txtSearchSalerName;
	protected Button btnSearch;
	protected UpdatePanel UpdatePanel1;
	protected Repeater rptList;
	protected Literal ltrPagePanel;
	protected UpdatePanel upList;
	private string linkHead = "";
	private string beforeurl = "Admin_JXC_AccountSubjectDetailMoney.aspx?MenuName=财务管理&FileName=明细分类账";
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(43))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_JXC_AccountSubjectTotal");
				base.WriteRightErrMsg();
			}
			string sql = "select top 1  DATEPART (YYYY,InputDate) as yearNum from HLJXC_View_AccountAoucherItemSubjcet order by DATEPART (YYYY,InputDate) asc";
			DataTable dataTable = this.conn.GetDataTable(sql);
			int year = DateTime.Now.Year;
			this.ddlYear.Items.Clear();
			if (dataTable.Rows.Count > 0)
			{
				int num = Convert.ToInt32(dataTable.Rows[0]["yearNum"].ToString());
				if (num < year)
				{
					for (int i = num; i <= year; i++)
					{
						ListItem item = new ListItem(i.ToString(), i.ToString());
						this.ddlYear.Items.Add(item);
					}
				}
				else
				{
					this.ddlYear.Items.Add(new ListItem(year.ToString(), year.ToString()));
				}
			}
			else
			{
				this.ddlYear.Items.Add(new ListItem(year.ToString(), year.ToString()));
			}
			this.ddlSubjcetList();
			this.BindData();
		}
	}
	private void ddlSubjcetList()
	{
		this.ddlSubject.Items.Clear();
		string strWhere = "AccountSParentID=0 order by AccountSRootID,AccountSParentID desc";
		DataTable dataTable = BLLInstance.BllAccountSubject.GetList(strWhere).Tables[0];
		foreach (DataRow dataRow in dataTable.Rows)
		{
			int parentID = dataRow["AccountSubjectID"].ToInt32(new int[0]);
			BLLInstance.BllAccountSubject.BindSubjcet(this.ddlSubject, parentID, 1, "");
		}
		this.ddlSubject.Items.Insert(0, new ListItem("全部", "0"));
	}
	protected string GetQuery()
	{
		string text = " where 1=1 ";
		string text2 = Fetch.Get("selYear");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddlYear.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddlYear.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text2))
		{
			text = text + " and (DATEPART (YYYY,InputDate)=" + text2 + ")";
			this.linkHead = this.linkHead + "&selYear=" + text2;
		}
		string text3 = Fetch.Get("BeginMonth");
		if (!string.IsNullOrEmpty(text3))
		{
			this.ddlBeginMonth.ddlSelect(text3);
		}
		else
		{
			text3 = this.ddlBeginMonth.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and DATEPART(MM,InputDate)>=" + text3;
			this.linkHead = this.linkHead + "&BeginMonth=" + text3;
		}
		string text4 = Fetch.Get("EndMonth");
		if (!string.IsNullOrEmpty(text4))
		{
			this.ddlEndMonth.ddlSelect(text4);
		}
		else
		{
			text4 = this.ddlEndMonth.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text4))
		{
			if (!string.IsNullOrEmpty(text3))
			{
				if (Convert.ToInt32(text3) > Convert.ToInt32(text4))
				{
					this.WriteErrMsg("", "开始的月份不能大于结束月份！", "");
				}
			}
			text = text + " and DATEPART(MM,InputDate)<=" + text4;
			this.linkHead = this.linkHead + "&EndMonth=" + text4;
		}
		string text5 = Fetch.Get("subjcetID");
		if (!string.IsNullOrEmpty(text5))
		{
			this.ddlSubject.ddlSelect(text5);
		}
		else
		{
			text5 = this.ddlSubject.SelectedValue;
		}
		if (!string.IsNullOrEmpty(text5) && text5 != "0")
		{
			text = text + " and AAItemAccountSID=" + text5;
			this.linkHead = this.linkHead + "&subjcetID=" + text5;
		}
		string text6 = Fetch.Get("ownername");
		if (!string.IsNullOrEmpty(text6))
		{
			this.txtSearchSalerName.Text = text6;
		}
		else
		{
			text6 = this.txtSearchSalerName.Text;
		}
		if (!string.IsNullOrEmpty(text6))
		{
			text = text + " and OwnerID in (select UserID from HL_User where UserName like '%" + text6 + "%')";
			this.linkHead = this.linkHead + "&ownername=" + text6;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by AccountAoucherID asc";
	}
	public void BindData()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = 0;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		DataTable listAccountAoucherItemSubjcetContainOwnerName = BLLInstance.BllAccountAoucher.GetListAccountAoucherItemSubjcetContainOwnerName(query);
		DataTable dataTable = BLLInstance.BllAccountAoucher.GetNewDataSet(listAccountAoucherItemSubjcetContainOwnerName, false).Tables[0];
		int num2 = 10;
		int count = dataTable.Rows.Count;
		this.rptList.DataSource = CurrPageLinks.instance.GetPagedTable(dataTable, num, num2);
		this.rptList.DataBind();
		decimal d = 0m;
		decimal num3 = 0m;
		decimal d2 = 0m;
		for (int i = 0; i < this.rptList.Items.Count; i++)
		{
			Label label = (Label)this.rptList.Items[i].FindControl("lblRow");
			Label label2 = (Label)this.rptList.Items[i].FindControl("lblBorrowPrice");
			Label label3 = (Label)this.rptList.Items[i].FindControl("lblLoanPrice");
			HiddenField hiddenField = (HiddenField)this.rptList.Items[i].FindControl("hfBorrowPrice");
			HiddenField hiddenField2 = (HiddenField)this.rptList.Items[i].FindControl("hfLoanPrice");
			Label label4 = (Label)this.rptList.Items[i].FindControl("lblLend");
			Label label5 = (Label)this.rptList.Items[i].FindControl("lblMoney");
			int num4 = i + 1;
			if (num > 0)
			{
				num4 = (num - 1) * num2 + num4;
			}
			label.Text = num4.ToString();
			if (label5 != null)
			{
				decimal num5 = 0m;
				if (!string.IsNullOrEmpty(hiddenField.Value))
				{
					num5 = Convert.ToDecimal(hiddenField.Value);
				}
				decimal num6 = 0m;
				if (!string.IsNullOrEmpty(hiddenField2.Value))
				{
					num6 = Convert.ToDecimal(hiddenField2.Value);
				}
				decimal d3 = 0m;
				if (num5 > 0m && num6 == 0m)
				{
					label2.Text = num5.ToString();
					label3.Text = "";
					label4.Text = "借";
					label5.Text = num5.ToString();
					d3 = num5;
				}
				else
				{
					if (num5 == 0m && num6 > 0m)
					{
						label2.Text = "";
						label3.Text = num6.ToString();
						label4.Text = "贷";
						label5.Text = num6.ToString();
						d3 = num6;
					}
				}
				d += num5;
				num3 += num6;
				d2 += d3;
			}
		}
		Label label6 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalBorrowPrice");
		Label label7 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalLoanPrice");
		Label label8 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalLend");
		Label label9 = (Label)this.rptList.Controls[this.rptList.Controls.Count - 1].FindControl("lblTotalMoney");
		decimal num7 = d - num3;
		if (num7 > 0m)
		{
			label8.Text = "借";
		}
		else
		{
			if (num7 < 0m)
			{
				label8.Text = "贷";
			}
			else
			{
				if (num7 == 0m)
				{
					label8.Text = "平";
				}
			}
		}
		label6.Text = d.ToString();
		label7.Text = num3.ToString();
		label9.Text = Math.Abs(num7).ToString();
		if (this.rptList.Items.Count == 0)
		{
			label8.Text = "";
		}
		string url = this.beforeurl + this.linkHead + "&pageindex";
		this.ltrPagePanel.Text = CurrPageLinks.instance.CurrPageLinkStr(num, num2, count, "条记录&nbsp;每页" + num2 + "条记录&nbsp;", url, true);
	}
	protected void btnSearch_Click(object sender, EventArgs e)
	{
		this.BindData();
	}
	protected void ddlSubject_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.BindData();
	}
}
